package MOLE.Bill;

import MOLE.userpkg.*;
import DataAccess.*;
import MOLE.*;

/** 
 Account ��ժҪ˵����
*/
public class Account extends App.Account
{

	public java.math.BigDecimal PrechargeMoney = new java.math.BigDecimal(0);
	public java.math.BigDecimal PayTotalMoney = new java.math.BigDecimal(0);
//	public Decimal BingoTotalMoney=0;
	public java.math.BigDecimal YonjenTotalMoney = new java.math.BigDecimal(0);
	public java.math.BigDecimal TisyeTotalMoney = new java.math.BigDecimal(0);
	public String OwenerName = "notdecide";
	//public 

	public Account(int uid)
	{
		//
		// TODO: �ڴ˴���ӹ��캯���߼�
		//
		Uid = uid;
		AccountOwnerName = "xx";


		// zt='q' and
		String text = "select *  from bank where hy_num=" + Uid.toString();
		System.Data.DataTable dt = MOLE.SQL.GetDataTable(text);
		if (dt.Rows.size() != 0)
		{

			this.AccountOwnerName = dt.Rows[0]["hy_name"].toString();
			this.OwenerName = this.AccountOwnerName;
			java.math.BigDecimal d = MOLE.str.ConverToDecimal(dt.Rows[0]["output_money"].toString());
			 PayTotalMoney = Math.abs(d);
	//		PrechargeMoney= MOLE.str.ConverToDecimal( dt.Rows[0]["input_money"].ToString() ) ;
			Balance = MOLE.str.ConvertToDouble(dt.Rows[0]["balance"].toString().trim());
	//		TisyeTotalMoney = _GetTisyeMoney();
		//	YonjenTotalMoney = _GetYonjen();
		}

	}

	public final void iniacc(int uid)
	{


	}

	public final void addmoney(String uname)
	{


	}

	public final void iniacc(String uname)
	{
		if (existAcc(uname))
		{

		}
		else
		{
			userx uc = new userx();
		hy_info u = uc.getuser(uname);


			String text = "insert into   bank(Balance,output_money,hy_num,hy_name)values(0,0,@uid,@uname)";
			SqlParameter[] para = new SqlParameter[]
			{
				new SqlParameter("@uid", u.getHy_Num()),
				new SqlParameter("@uname", uname)
			};
			MOLE.SQL.ExecuteSql(text, para);

		}

	}

	private boolean existAcc(String uname)
	{
		String text = "select *  from bank where  hy_name=@unaem";
		SqlParameter[] para = new SqlParameter[] {new SqlParameter("@unaem", uname)};
  DataTable d = MOLE.SQL.GetDataTable(text, para);
  if (d.Rows.size() == 0)
  {
	  return false;
  }
  else
  {
	  return true;
  }
	}
	public Account()
	{
	}

	public final java.math.BigDecimal _GetBingoTotalMoney()
	{
		return 0;

	}

	public final java.math.BigDecimal _GetTisyeMoney()
	{

		String text2 = "select sum(money) as summoney from bank_tixian where zt='\u5df2\u5904\u7406' and hy_num=" + Uid.toString();
		String t = MOLE.SQLOS._GetFieldValue("summoney", text2);
		return MOLE.str.ConverToDecimal(t);

	}

	public final java.math.BigDecimal GetTisyeTotalMoney()
	{


		 java.math.BigDecimal r = new java.math.BigDecimal(0);

		String s = "exec  Account_GetTisyeTotalMoney   " + String.valueOf(this.Uid);
		DataTable d = MOLE.SQL.GetDataTable(s);
		try
		{
			r = (java.math.BigDecimal)(d.Rows[0]["money"].toString());
		}
		catch (java.lang.Exception e)
		{
		}


		return r;


	}


	public final java.math.BigDecimal _GetYonjen()
	{

		 String sql = "select sum(totalprice) as TeuzhuTotalMoney from agentdg where zt<>'����Ʊ' and zt<>'' and zt is not null and agent_id=" + Uid.toString();
		java.math.BigDecimal chupiaoOkMoney = MOLE.str.ConverToDecimal(MOLE.SQLOS._GetFieldValue("TeuzhuTotalMoney", sql));
		double fediBily = (new User(Uid)).FandianBili;

		java.math.BigDecimal r = chupiaoOkMoney.multiply((java.math.BigDecimal)fediBily);
		  return r;
	}

	public final java.math.BigDecimal GetBingoTotalMoney()
	{
		String sql = "select sum(zj_jiangjin) as Money from agentdg where  agent_id=" + Uid.toString();
		java.math.BigDecimal r = MOLE.str.ConverToDecimal(MOLE.SQLOS._GetFieldValue("Money", sql));
		return r;


	}

	public static String ShowPayOrCharge(String money, String type)
	{
		java.math.BigDecimal m = MOLE.str.ConverToDecimal(money);
		if (type.equals("pay"))
		{
			if (m.compareTo(0) >= 0)
			{
				return "--";
			}
			else
			{
				return String.format("%0.2f", m);
			}

		}
		else
		{
			if (m.compareTo(0) > 0)
			{
				return String.format("%0.2f", m);
			}
			else
			{
				return "--";
			}
		}



	}


	public static DataTable GetDetailList(int uid)
	{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
			 ///#region
		String sql = " select  top 1000000 *    from   banklogView ";
		if (uid == 0)
		{
			sql = sql + " where 1=1 ";
		}
		else
		{
			sql += " where hy_num=" + String.valueOf(uid);
		}

		sql += " order by  id  desc";

		DataTable d = MOLE.SQL.GetDataTable(sql);
		return d;


//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
			///#endregion
	}







}